import 'package:flutter_shop_z/model/commodity.dart';

class CommodityCart extends Commodity {
  int number; //购买的数量
  bool isCheck = true; //购买的数量
  CommodityCart({this.number, this.isCheck});
  Map toJson() {
    Map map = super.toJson();
    map["number"] = this.number;
    map["isCheck"] = this.isCheck;
    return map;
  }

  static CommodityCart toCart(Commodity commodity) {
    CommodityCart cart = new CommodityCart();
    cart.number = 1;
    cart.isCheck = true;
    cart.commodityId = commodity.commodityId;
    cart.commodityName = commodity.commodityName;
    cart.commodityDescribe = commodity.commodityDescribe;
    cart.commodityImg = commodity.commodityImg;
    cart.commodityImgMedium = commodity.commodityImgMedium;
    cart.commodityImgBig = commodity.commodityImgBig;
    cart.commodityOriginalPrice = commodity.commodityOriginalPrice;
    cart.commodityDiscountPrice = commodity.commodityDiscountPrice;
    cart.commodityCreateTime = commodity.commodityCreateTime;
    cart.categoryId = commodity.categoryId;
    cart.categorySubId = commodity.categorySubId;
    cart.commodityImg1 = commodity.commodityImg1;
    cart.commodityImg2 = commodity.commodityImg2;
    cart.commodityImg3 = commodity.commodityImg3;
    cart.commodityImg4 = commodity.commodityImg4;
    cart.commodityImgDetails1 = commodity.commodityImgDetails1;
    cart.commodityImgDetails2 = commodity.commodityImgDetails2;
    cart.commodityImgDetails3 = commodity.commodityImgDetails3;
    cart.commodityImgDetails4 = commodity.commodityImgDetails4;
    return cart;
  }

  factory CommodityCart.fromJson(dynamic json) {
    CommodityCart cart = CommodityCart();
    Commodity commodity = Commodity.fromJson(json);
    if (json['number'] == null) {
      cart.number = 1;
    } else {
      cart.number = json['number'];
    }

    if (json['isCheck'] == null) {
      cart.isCheck = true;
    } else {
      cart.isCheck = json['isCheck'];
    }

    cart.commodityId = commodity.commodityId;
    cart.commodityName = commodity.commodityName;
    cart.commodityDescribe = commodity.commodityDescribe;
    cart.commodityImg = commodity.commodityImg;
    cart.commodityImgMedium = commodity.commodityImgMedium;
    cart.commodityImgBig = commodity.commodityImgBig;
    cart.commodityOriginalPrice = commodity.commodityOriginalPrice;
    cart.commodityDiscountPrice = commodity.commodityDiscountPrice;
    cart.commodityCreateTime = commodity.commodityCreateTime;
    cart.categoryId = commodity.categoryId;
    cart.categorySubId = commodity.categorySubId;
    cart.commodityImg1 = commodity.commodityImg1;
    cart.commodityImg2 = commodity.commodityImg2;
    cart.commodityImg3 = commodity.commodityImg3;
    cart.commodityImg4 = commodity.commodityImg4;
    cart.commodityImgDetails1 = commodity.commodityImgDetails1;
    cart.commodityImgDetails2 = commodity.commodityImgDetails2;
    cart.commodityImgDetails3 = commodity.commodityImgDetails3;
    cart.commodityImgDetails4 = commodity.commodityImgDetails4;
    return cart;
  }
}
